package com.lovo.dao.impl;

import com.lovo.bean.Classz;
import com.lovo.bean.User;
import com.lovo.dao.BaseDAO;
import com.lovo.dao.ClassDAO;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ClassDAOImpl extends BaseDAO implements ClassDAO {
    @Override
    public List<Classz> find() {
        PreparedStatement statement = null;
        ResultSet result = null;
        List list = new ArrayList();
        try {
            String sql = "select * from t_class ";
            statement = con.prepareStatement(sql);
            result = statement.executeQuery();
            while(result.next()){
                list.add(fillClass(result));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.close(con,statement,result);
        }
        return list;
    }
    private Classz fillClass(ResultSet rs) throws SQLException {
        Classz classz = new Classz();
        classz.setId(rs.getInt("c_id"));
        classz.setName(rs.getString("c_name"));
        classz.setTeacher(rs.getString("c_teacher"));
        classz.setCreateDate(rs.getString("c_create_time"));
        return classz;
    }

    public static void main(String[] args) {
        ClassDAO classDAO = new ClassDAOImpl();
        System.out.println(classDAO.find());
    }
}
